package com.project.restaurant.common;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@EnableSwagger2WebMvc
@EnableKnife4j//启用swagger文档
@AutoConfiguration//交给SpringBoot托管
public class SwaggerConfig {

    @Bean
    public Docket getDocket(){
//        docket封装接口文档信息

        //封面信息
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        apiInfoBuilder.title("西餐厅后端文档")
                .description("此文档详细说明了西餐厅后端接口规范")
                .version("v 0.0.1-SNAPSHOT")
                .contact(new Contact("hzp","https://gitee.com/leisurely-leisurely/restaurant","1031155817@qq.com"));
        ApiInfo apiInfo = apiInfoBuilder.build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .groupName("restaurant")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.project.restaurant"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

